package com.red.star.wechat.data.mappers;

import com.red.star.wechat.data.core.base.MyMapper;
import com.red.star.wechat.data.entity.ImageView;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author xuquanyu
 * @date 2018/8/16.
 * 图片管理
 */
public interface ImageViewMapper extends MyMapper<ImageView> {

    List<ImageView> imageViewList(ImageView imageView);

    List<ImageView> imageViewDetailByCondition(ImageView imageView);

    @Select(value = "select * from t_image_view t where t.fans_id = #{fansId} and t.employee_id = #{employeeId} and mall_code=#{mallCode}")
    ImageView checkImageViewIsExist(@Param("fansId") Integer fansId, @Param("employeeId") Integer employeeId, @Param("mallCode") String mallCode);

    @Select(value = "select * from t_image_view t where t.fans_id = #{fansId}and mall_code=#{mallCode}")
    ImageView checkImageViewIsExistTwo(@Param("fansId") Integer fansId, @Param("mallCode") String mallCode);


    ImageView findIsEdited(@Param("fansId") Integer fansId);

    ImageView findIsEditedTwo(@Param("fansId") Integer fansId, @Param("employeeId") Integer employeeId);

    ImageView showImage(@Param("id") Integer id);

    /**
     * 查询未完成的图片编辑
     *
     * @param id
     * @return
     */
    @Select("SELECT * FROM t_image_view WHERE fans_id = #{fansId} AND step != 6")
    ImageView findUnfinishImageView(Integer id);

    @Select("select t.id from t_image_view t where t.step = 6")
    List<Integer> findFinishedId();

    /**
     * 根据id修改步骤数  back
     *
     * @param imageViewId
     * @return
     */
    @Update("update t_image_view set step = step - 1 where id = #{imageViewId}")
    int updateStepById(@Param("imageViewId") Integer imageViewId);

    /**
     * 根据id查询步骤
     *
     * @param imageViewId
     * @return
     */
    @Select("select step from t_image_view where id = #{imageViewId}")
    Integer findStepById(@Param("imageViewId") Integer imageViewId);
}
